package com.weimob.mcloud.wechatwork.customer.convertor.customer;

import com.weimob.mcloud.wechatwork.core.entity.relation.CustomerEmployeeRelation;
import com.weimob.mcloud.wechatwork.core.entity.relation.employee.Employee;
import org.apache.commons.collections.CollectionUtils;

import java.util.*;

/**
 * @author yuanhao
 * @date 2022/8/26 14:55
 */
public class RelationConvert {


    /**
     * 合并vidList
     * @param relationList  客户员工关系
     * @return vidList
     */
    public static List<Long> mergeVidList(List<CustomerEmployeeRelation>  relationList) {
        if(CollectionUtils.isEmpty(relationList)){
            return new ArrayList<>();
        }
        //使用set合并员工所属vid节点和上级vid节点，防止重复ss
        Set<Long> finalVids = new HashSet<>();
        for (CustomerEmployeeRelation relation : relationList) {
            Employee employee = relation.getEmployee();
            if(Objects.isNull(employee)){
                continue;
            }
            if (CollectionUtils.isNotEmpty(employee.getVidList())) {
                finalVids.addAll(employee.getVidList());
            }
            if (CollectionUtils.isNotEmpty(employee.getHigherVidList())) {
                finalVids.addAll(employee.getHigherVidList());
            }
        }
        return new ArrayList<>(finalVids);
    }
}
